<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>修改密码</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../css/user.css" media="all" />
</head>
<body class="childrenBody">
	<form class="layui-form changePwd" id="changePwd">
		<div class="layui-form-item">
		    <label class="layui-form-label">用户名</label>
		    <div class="layui-input-block">
		    	<input type="text" th:value="${session.admin.getUsername()}" disabled class="layui-input layui-disabled">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">旧密码</label>
		    <div class="layui-input-block">
		    	<input type="password" value="" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd" id="oldpwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">新密码</label>
		    <div class="layui-input-block">
		    	<input type="password" value="" placeholder="请输入新密码" lay-verify="required|newPwd" class="layui-input pwd" id="newpwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">确认密码</label>
		    <div class="layui-input-block">
		    	<input type="password" value="" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd" id="Nnewpwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <div class="layui-input-block">
		    	<a class="layui-btn layui-btn-normal"  lay-filter="changePwd" id="modify">立即修改</a>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</div>
	</form>
	<script type="text/javascript" src="../layui/layui.js"></script>
	<script type="text/javascript" src="../js/jquery-1.8.2.min.js" ></script>
	<script>
		layui.use('layer', function() {
		$("#modify").click(function(){
			
			
							if($("#oldpwd").val() == ""){
								layer.msg('请输入旧密码', {icon: 2});
								return;
							}
							if($("#newpwd").val() == ""){
								layer.msg('请输入新密码', {icon: 2});
								return;
							}
							if($("#Nnewpwd").val() == ""){
								layer.msg('请输入确认新密码', {icon:2});
								return;
							}			
							if($("#newpwd").val() != $("#Nnewpwd").val()){
								layer.msg('两次密码输入不一致', {icon: 2});
								return;
							}
			
				$.ajax({
					type: "post",
			        url: "../admin/modifyPassword",
			        data: {
			        	oldPassword:$("#oldpwd").val(),
			        	newPassword:$("#newpwd").val(),
			  	  },
			  	  dataType: "json",
			  	  success: function(data){
					if (data.code==0) {
						/*layer.msg('修改成功', {icon: 1});*/
						var index = parent.layer.getFrameIndex(window.name);
							var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
							        
							        setTimeout(function(){
							            top.layer.close(index);
							      top.layer.msg("密码修改成功！");
							       layer.closeAll("iframe");
							        },1000);
							         setTimeout(function(){
							           parent.location.reload();
							        },1500);
							    
							       
						$('#changePwd')[0].reset();
					} else {
						layer.msg(data.msg, {icon: 2});
						$('#changePwd')[0].reset();
					}
			  	  }
			  });
			
			});
			
		});
	</script>
</body>
</html>